home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / DRAWPOLY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.3 KB  |  55 lines

  1.  
  2.                                         /* File       : drawpoly.c */
  3.                                         /* Entered by : A. Wayner */
  4. # include <graphics.h>
  5. # include <stdlib.h>
  6.  
  7. int y[5] = {2, 1, 4, 5, 4 };
  8. int x[5] = {10, 20, 30, 40, 50};
  9.  
  10. main()
  11. {
  12.     int graphdriver = DETECT, graphmode, i,
  13.          maxy = 5,
  14.          maxx = 50,
  15.          numpt,
  16.          maxheight, maxwidth, xscale, yscale,
  17.          plotdata[10];
  18.  
  19.     numpt = sizeof( y ) / sizeof( int );
  20.  
  21.  
  22.                                             /* Detect adapter type and initialize */
  23.                                             /* graphics system */
  24.     initgraph( &graphdriver, &graphmode, "\\turboc" );
  25.     settextstyle( TRIPLEX_FONT, HORIZ_DIR, 2 );
  26.     outtextxy( 100, 10, "x-y graphs using 'drawpoly'");
  27.  
  28.                                            /* Now draw the x-y graph */
  29.     maxheight = getmaxy() - 100;
  30.     yscale = maxheight / maxy;
  31.  
  32.     maxwidth = getmaxx() - 300;
  33.     xscale   = maxwidth / maxx;
  34.  
  35.  
  36.     setviewport( 100, 50, 100 + maxwidth, 50 + maxheight, 1 );
  37.     rectangle( 0,0, maxwidth, maxheight );
  38.  
  39.                                             /* Scale the data points to fit */
  40.                                             /*  in assigned area */
  41.     for( i = 0; i < numpt; i++ )
  42.     {
  43.         plotdata[2*i]   =              x[i]*xscale ;
  44.                                             /* Our y-coordinates increase as we go up */
  45.         plotdata[2*i+1] =  maxheight - y[i]*yscale;
  46.     }
  47.  
  48.     drawpoly( numpt, plotdata );      /* Use drawpoly to display the graph */
  49.  
  50.     getch();
  51.     closegraph();
  52. }
  53.  
  54.  
  55.